﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability.Infratruvture.Interfares;

namespace Traceability.Infratruvture.Implement
{
    public class BaseRequsitory<T> : IBaseRequsitory<T> where T : class, new()
    {

        private readonly SCDbCotext db;

        public BaseRequsitory(SCDbCotext db)
        {
            this.db = db;
        }

        public Task<int> AddAsync(T t)
        {
            db.Set<T>().AddAsync(t);
            return db.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public Task<int> UpdateAsync(T t)
        {
            db.Set<T>().Update(t);
            return db.SaveChangesAsync();
        }

        Task<int> IBaseRequsitory<T>.DeleteAsync(int id)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int Del(T t)
        {
            db.Set<T>().Remove(t);
            return db.SaveChanges();
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">实体</param>
        /// <returns>返回受影响行数</returns>
        public Task<int> DeleteAsync(int id)
        {
            throw new NotImplementedException();
        }
    }
}
